import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // id 是数组对象中的唯一标识
    tableData: [{
      cityId: '001',
      cityName: '北京',
      id: 0
    }, {
      cityId: '002',
      cityName: '上海',
      id: 1
    }, {
      cityId: '001',
      cityName: '北京',
      id: 2
    }],
    citys: [
      {
        cityId: '001',
        cityName: '北京',
      },
      {
        cityId: '002',
        cityName: '上海',
      },
      {
        cityId: '003',
        cityName: '广州',
      },
      {
        cityId: '004',
        cityName: '深圳',
      },
      {
        cityId: '005',
        cityName: '杭州',
      },
      {
        cityId: '006',
        cityName: '西安',
      }
    ],
    currendIndex:null,
    currendCity:null
  },
  mutations: {
    changeIndex(state,paylod){
      state.currendIndex = paylod
    },
    changeItemCity(state,paylod){
      state.tableData[state.currendIndex] = Object.assign({},state.tableData[state.currendIndex],paylod)
    },
    changeCity(state, paylod){
      state.currendCity = paylod
    }
  },
  actions: {
  },
  modules: {
  }
})

const state = {
  // 这里存一个你点击【出差地点】的时候的index   为了将来你在那边点击之后操作数组里面的哪一项
  // city: '北京'
  currendIndex:null 

}
const actions = {
  changeCity(ctx, city) {
    ctx.commit('changeCity', city)
  }
}

const mutations = {
  changeCity(state, city) {
    state.city = city
  }
}
